<template>
  <div>
    <Icon
      v-if="!cabinet.sites[props.renderRow.siteName]"
      :name="state.Icon"
      style="cursor: pointer"
      @click="getSiteName"
    />
    <el-tag v-else>
      {{ cabinet.sites[props.renderRow.siteName] }}
    </el-tag>
  </div>
</template>
<script lang="ts" setup>
import _ from "lodash";
import { onMounted, reactive, inject } from "vue";
import type { TableColumn, TableRow, OptButton } from "@/utils/baTable"; //表格列行类型
import { ElNotification } from "element-plus"; //处理导航信息

const gateway = inject("gateway") as any;
const cabinet = inject("cabinet") as any;

// BuildAdmin将自动为此组件传递五个Props
interface Props {
  renderValue: any; // 单元格值
  renderRow: TableRow; // 当前行数据
  renderField: TableColumn; // 当前列数据
}

const props = withDefaults(defineProps<Props>(), {});

const state: { Icon: any; type: string; siteNameOfArea: string } = reactive({
  Icon: "el-icon-Pointer",
  type: "",
  siteNameOfArea: "",
});

//查询机柜管理获取机柜的所属站点
const getSiteName = () => {
  cabinet
    .getElectricNormalData({ cabinetName: props.renderRow.siteName })
    .then((res: any) => {
      if (res.rows.length > 0) {
        if (
          JSON.stringify(cabinet.sites) == "{}" ||
          !JSON.stringify(cabinet.sites[props.renderRow.siteName])
        ) {
          cabinet.sites[props.renderRow.siteName] = res.rows[0].siteName;
        }
      } else {
        ElNotification({
          type: "warning",
          offset: 100,
          // dangerouslyUseHTMLString: true,
          message: "站点查询为空 请先绑定机柜",
        });
      }
      console.log(
        "props.renderRow.siteName",
        props.renderRow.siteName,
        cabinet.sites
      );
    });
};

onMounted(() => {
  console.log("当前行数据", props.renderRow, "当前列数据", props.renderField);
  console.log(
    "props.renderRow.siteName",
    props.renderRow.siteName,
    cabinet.sites
  );
});
</script>
<style lang="scss" scoped></style>
